<?php

namespace App\Dao\System;

use App\Model\System\SystemFile;
use \Yj\Daos\BaseDao;
use Hyperf\Database\Model\Builder;
use Yj\Daos\Verify;

/**
 * @var SystemFile
 */
class SystemFileDao extends BaseDao
{

    public function DaoWhere(array $params)
    {
        return $this->getDaoQuery($params, function (Verify $verify) {
            $verify('tags_id', function (Builder $query, $tags_id) {
                $query->where('tags_id', $tags_id);
            });
//            $verify('title', function (Builder $query, $title) {
//                $query->where('title', $title);
//            });
        });
    }

    public function lists(\Hyperf\Utils\Collection $params)
    {
        return $this->DaoWhere($params->toArray())->getList();
    }

    public function getFullPath($id)
    {
        if (is_array($id)) {
            $data = $this->whereIn('id', $id)->pluck('path')->toArray();
            $data = array_map(function ($item) {
                return $this->url($item);
            }, $data);
            return $data;
        } else {
            return $id ? $this->url($this->where('id', $id)->value('path')) : '';
        }
    }

    public function url($path)
    {
        return $path ? systemConfig('site_url') . $path : '';
    }

}